package com.nlx.notes.module.controller.system;

import com.nlx.notes.module.bean.dto.system.SystemConfigUpdateDTO;
import com.nlx.notes.module.bean.vo.system.SystemConfigVO;
import com.nlx.notes.module.core.util.JSONUtils;
import com.nlx.notes.module.service.system.ISystemPreferencesService;
import com.nlx.notes.support.context.UserHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 用户的配置项信息 前端控制器
 * </p>
 *
 * @author nlx
 * @since 2025-08-24
 */
@Slf4j
@RestController
@RequestMapping("/system")
@RequiredArgsConstructor
public class SystemPreferencesController {

    final ISystemPreferencesService systemPreferencesService;

    @GetMapping(value = "/config")
    public List<SystemConfigVO> systemConfigList(@RequestParam(value = "type",defaultValue = "all",required = false) String type){
        log.info("查询系统参数信息，用户：{}", UserHolder.getUserContext().getId());
        return systemPreferencesService.getSystemConfigList(type,UserHolder.getUserContext().getId());
    }


    @PostMapping(value = "/update")
    public SystemConfigVO updateConfigConfig(@RequestBody SystemConfigUpdateDTO systemConfigUpdateDTO){
        log.info("修改参数，用户：{}，参数：{}", UserHolder.getUserContext().getId(), JSONUtils.toString(systemConfigUpdateDTO));
        systemConfigUpdateDTO.setUserId(UserHolder.getUserContext().getId());
        return systemPreferencesService.updateConfigConfig(systemConfigUpdateDTO);
    }

}
